import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';

export const Layout = () => import('@/Layout/index.vue');

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
    {
        path: '/:lang(en)?',
        component: Layout,
        redirect: to => {
            return { path: '/' + to.params.lang };
        },
        children: [
            {
                path: '',
                component: () => import('@/pages/home/index.vue'),
                name: 'home',
                meta: {
                    title: 'home',
                    isShowNav: false,
                    isTabbar: true,
                    icon: 'wap-home-o',
                },
            },
            {
                path: 'instruction',
                component: () => import('@/pages/instruction/index.vue'),
                name: 'instruction',
                meta: {
                    title: 'instruction',
                    isShowNav: true,
                    isTabbar: true,
                    icon: 'todo-list-o',
                },
            },
            {
                path: 'instruction/detail',
                component: () => import('@/pages/instruction/detail.vue'),
                name: 'instructionDetail',
                meta: {
                    title: 'instruction',
                    isShowNav: true,
                    isBack: true,
                },
            },
            {
                path: 'video/:id',
                component: () => import('@/pages/video/index.vue'),
                name: 'video',
                meta: { title: 'video', isShowNav: true, isBack: true },
            },
            {
                path: 'color-page',
                component: () => import('@/pages/color-page/index.vue'),
                name: 'EColorPage',
                meta: {
                    title: 'EColorPage',
                    isShowNav: true,
                    isTabbar: true,
                    icon: 'user-circle-o',
                },
            },
        ],
    },
];

/**
 * 创建路由
 */
const router = createRouter({
    history: createWebHistory(),
    routes: constantRoutes,
    // 刷新时，滚动条位置还原
    scrollBehavior: () => ({ left: 0, top: 0 }),
});

export default router;
